home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Hot Mix 17
/
Hot Mix 17.iso
/
HM17_SGI
/
research
/
examples
/
insight
/
plugins
/
myvis.pro
< prev
Wrap
Text File
|
1997-07-08
|
15KB
|
428 lines
; $Id: myvis.pro,v 1.8 1997/04/23 17:11:13 rob Exp $
;
; Copyright (c) 1997, Research Systems, Inc. All rights reserved.
; Unauthorized reproduction prohibited.
;+
; FILE:
; myvis.pro
;
; PURPOSE:
; This file contains an example Analysis PlugIn that visualizes data.
;
; CONTENTS:
; GENERAL ROUTINES
; pro SensitizeMyVis - set widget sensitivity
; pro HandleEventsMyVis - handle dialog box events
;
; CALLBACK ROUTINES
; fun ApplyMyVis - Apply/OK entry point
; fun PromptUserMyVis - main entry point (creates dialog)
;
; REGISTRATION FUNCTION
; fun MyVis - registers the PlugIn
;
;-
; *****************************************************************************
; GENERAL ROUTINES
; *****************************************************************************
; -----------------------------------------------------------------------------
;
; Purpose: Set widget sensitivity.
;
pro SensitizeMyVis
; Widget state information.
;
common MyVisCommon, psState
; Set sensitivity and value shown for visualization insert.
;
visIndex = (*psState).visIndex
visType = (*psState).visTypes[visIndex]
sensitive = (visType eq 'plot')
WIDGET_CONTROL, (*psState).wInsertBgroup, SENSITIVE=sensitive
if (sensitive) then $
WIDGET_CONTROL, (*psState).wInsertBgroup, $
SET_VALUE=((*psState).insert) $
else $
WIDGET_CONTROL, (*psState).wInsertBgroup, SET_VALUE=0
end ; SensitizeMyVis
; -----------------------------------------------------------------------------
;
; Purpose: Handle dialog events.
;
pro HandleEventsMyVis, sEvent
; Widget state information.
;
common MyVisCommon, psState
wGroup = (*psState).wMainBase
; Catch errors.
;
CATCH, error
if (error ne 0) then begin
CATCH, /CANCEL
void = DIALOG_MESSAGE(!ERR_STRING, DIALOG_PARENT=wGroup)
RETURN
endif
; ========================
; PROCESS EVENTS
; ========================
case (sEvent.id) of
; --------------------------------------
; Input text
; --------------------------------------
(*psState).wInput1Text: ; (nothing to do now)
(*psState).wInput2Text: ; (nothing to do now)
(*psState).wInput3Text: ; (nothing to do now)
; --------------------------------------
; Input browse buttons
; --------------------------------------
; Let user browser for a data name.
; If user selected an item, set data name in text widget.
;
(*psState).wInput1BrowseButton: begin
title = 'Select a data item.'
void = INSGET( $
NAME=name, $ ; returned name of data selected
/EXCLUSIVE, $ ; only one selection
TITLE=title, $ ; title of browser
COUNT=count, $ ; returned count of items selected
GROUP=wGroup, $ ; widget group leader
_EXTRA=(*psState).extra) ; extra information
if (count eq 1) then $
WIDGET_CONTROL, (*psState).wInput1Text, SET_VALUE=name
end
(*psState).wInput2BrowseButton: begin
title = 'Select a data item.'
void = INSGET( $
NAME=name, $ ; returned name of data selected
/EXCLUSIVE, $ ; only one selection
TITLE=title, $ ; title of browser
COUNT=count, $ ; returned count of items selected
GROUP=wGroup, $ ; widget group leader
_EXTRA=(*psState).extra) ; extra information
if (count eq 1) then $
WIDGET_CONTROL, (*psState).wInput2Text, SET_VALUE=name
end
(*psState).wInput3BrowseButton: begin
title = 'Select a data item.'
void = INSGET( $
NAME=name, $ ; returned name of data selected
/EXCLUSIVE, $ ; only one selection
TITLE=title, $ ; title of browser
COUNT=count, $ ; returned count of items selected
GROUP=wGroup, $ ; widget group leader
_EXTRA=(*psState).extra) ; extra information
if (count eq 1) then $
WIDGET_CONTROL, (*psState).wInput3Text, SET_VALUE=name
end
; --------------------------------------
; Vis droplist
; --------------------------------------
(*psState).wVisDroplist: begin
; Get the visualization index.
;
index = WIDGET_INFO((*psState).wVisDroplist, /DROPLIST_SELECT)
(*psState).visIndex = index
; Set widget sensitivity based on visualization selected.
;
SensitizeMyVis
end
; --------------------------------------
; Insert bgroup
; --------------------------------------
(*psState).wInsertBgroup: begin
WIDGET_CONTROL, (*psState).wInsertBgroup, GET_VALUE=value
(*psState).insert = value[0]
end
; --------------------------------------
; OK/Apply/Cancel buttons
; --------------------------------------
(*psState).wOKApplyCancelButtons: begin
; Destroy dialog on successful OK selection, or if user canceled.
;
if ((sEvent.type eq 'OK') or $
(sEvent.type eq 'Cancel')) then $
WIDGET_CONTROL, (*psState).wMainBase, /DESTROY
end
; --------------------------------------
; other events
; --------------------------------------
else: ; (do nothing)
endcase
end ; HandleEventsMyVis
; *****************************************************************************
; CALLBACK ROUTINES
; *****************************************************************************
; -----------------------------------------------------------------------------
;
; Purpose: Get data and visualize it.
; Fuction returns 1B on success, else 0B.
;
function ApplyMyVis, $
CIDs=CIDs, $ ; OUT: command ID list from INSPUT/INSVIS calls
DATA_NAME=dataName, $ ; IN: name of data selected in visualization window
_EXTRA=extra ; IN: information to pass to commands
; Widget state information.
;
common MyVisCommon, psState
wGroup = (*psState).wMainBase
; ---------------------------------------------------------
; Catch errors.
; ---------------------------------------------------------
CATCH, error
if (error ne 0) then begin
CATCH, /CANCEL
void = DIALOG_MESSAGE(!ERR_STRING, DIALOG_PARENT=wGroup)
RETURN, 0B
endif
; ---------------------------------------------------------
; Get inputs.
; ---------------------------------------------------------
; Get visualization type.
;
visIndex = (*psState).visIndex
visType = (*psState).visTypes[visIndex]
; Get all input data names.
;
WIDGET_CONTROL, (*psState).wInput1Text, GET_VALUE=value
input1Name = value[0]
WIDGET_CONTROL, (*psState).wInput2Text, GET_VALUE=value
input2Name = value[0]
WIDGET_CONTROL, (*psState).wInput3Text, GET_VALUE=value
input3Name = value[0]
; (Let INSVIS do error checking...
; only problem is that the messages won't use correct field names.)
; ---------------------------------------------------------
; Visualize data.
; ---------------------------------------------------------
; Set the visualization mode.
;
mode = 'new'
if ((visType eq 'plot') and ((*psState).insert)) then $
mode = 'insert'
; Visualize the data.
;
; (Notice you can pass an empty string or undefined value as
; the third, or the second and third arguments to INSVIS.)
;
INSVIS, $
input1Name, $ ; name of data item
input2Name, $ ; name of 2nd data item
input3Name, $ ; name of 3rd data item
TYPE = visType, $ ; visualization type
MODE = mode, $ ; insert | new | overlay
CIDs = CIDs, $ ; command ID list
GROUP = wGroup, $ ; widget group leader
_EXTRA = extra ; extra information
; ---------------------------------------------------------
; Successful return.
; ---------------------------------------------------------
RETURN, 1B
end ; ApplyMyVis
; -----------------------------------------------------------------------------
;
; Purpose: Main entry point for the PlugIn.
;
pro PromptUserMyVis, $
GROUP=wGroup, $ ; IN: group leader widget ID
DATA_NAME=dataName, $ ; IN: name of data selected in visualization window
_EXTRA=extra ; IN: various information
; Widget state information.
;
common MyVisCommon, psState
; Set visualization types.
;
visTypes = [ $
'plot', $
'scatter', $
'histogram', $
'polar', $
'contour', $
'image', $
'surface' $
]
visTypesTitles = [ $
'plot (Y [, X])' , $
'scatter (Y [, X])' , $
'histogram (Y [, X])' , $
'polar (R, T)' , $
'contour (Z [, X, Y])' , $
'image (I)' , $
'surface (Z [, X, Y])' $
]
visIndex = 0
; Create modal main base (non-sizable).
;
title = 'Analysis PlugIn Example - My Vis'
wMainBase = WIDGET_BASE(TITLE=title, GROUP_LEADER=wGroup, $
/COLUMN, /MODAL, /TLB_FRAME_ATTR)
value = [ $
'Specify data, choose how to visualize, ' + $
'then hit Apply or OK.' $
]
for i = 0, N_ELEMENTS(value)-1 do $
void = WIDGET_LABEL(wMainBase, VALUE=value[i])
; ------------------------------------------
; Create INPUTS widgets.
; ------------------------------------------
wInputsBase = WIDGET_BASE(wMainBase, /COLUMN, /FRAME)
void = WIDGET_LABEL(wInputsBase, VALUE='INPUTS')
xs = 40
wInput1DataBase = WIDGET_BASE(wInputsBase, /ROW)
void = WIDGET_LABEL(wInput1DataBase, VALUE='Input1: ')
wInput1Text = WIDGET_TEXT(wInput1DataBase, VALUE=dataName, /EDITABLE, $
XSIZE=xs)
wInput1BrowseButton = WIDGET_BUTTON(wInput1DataBase, VALUE=' Browse... ')
wInput2DataBase = WIDGET_BASE(wInputsBase, /ROW)
void = WIDGET_LABEL(wInput2DataBase, VALUE='Input2: ')
wInput2Text = WIDGET_TEXT(wInput2DataBase, VALUE='', /EDITABLE, XSIZE=xs)
wInput2BrowseButton = WIDGET_BUTTON(wInput2DataBase, VALUE=' Browse... ')
wInput3DataBase = WIDGET_BASE(wInputsBase, /ROW)
void = WIDGET_LABEL(wInput3DataBase, VALUE='Input3: ')
wInput3Text = WIDGET_TEXT(wInput3DataBase, VALUE='', /EDITABLE, XSIZE=xs)
wInput3BrowseButton = WIDGET_BUTTON(wInput3DataBase, VALUE=' Browse... ')
; ------------------------------------------
; Create OUTPUTS widgets.
; ------------------------------------------
wOutputsBase = WIDGET_BASE(wMainBase, /COLUMN, /FRAME)
value = ' OUTPUTS'
void = WIDGET_LABEL(wOutputsBase, VALUE=value)
; Create visualization droplist.
;
padding = ' '
wOutputsRowBase = WIDGET_BASE(wOutputsBase, /ROW)
void = WIDGET_LABEL(wOutputsRowBase, VALUE=padding)
wVisDroplist = WIDGET_DROPLIST(wOutputsRowBase, $
VALUE=visTypesTitles, TITLE='Visualization Type: ')
WIDGET_CONTROL, wVisDroplist, SET_DROPLIST_SELECT=visIndex
; Create insert checkbox.
;
insert = 0
void = WIDGET_LABEL(wOutputsRowBase, VALUE=padding)
wInsertBgroup = CW_BGROUP(wOutputsRowBase, ['Insert'], $
/NONEXCLUSIVE, SET_VALUE=insert)
; ------------------------------------------
; Create OK/Apply/Cancel buttons using special compound widget.
; (Must pass in main modal base, used to set default and cancel buttons.)
;
wOKApplyCancelButtons = CW_INSAPPLY(wMainBase, _EXTRA=extra)
; Create dialog state information.
;
sState = { $
extra: extra, $
visTypes: visTypes, $
visIndex: visIndex, $
wMainBase: wMainBase, $
wInput1Text: wInput1Text, wInput1BrowseButton: wInput1BrowseButton, $
wInput2Text: wInput2Text, wInput2BrowseButton: wInput2BrowseButton, $
wInput3Text: wInput3Text, wInput3BrowseButton: wInput3BrowseButton, $
wVisDroplist: wVisDroplist, $
wInsertBgroup: wInsertBgroup, insert: insert, $
wOKApplyCancelButtons: wOKApplyCancelButtons $
}
; Store the state in a heap variable.
;
psState = PTR_NEW(sState, /NO_COPY)
; Set widget (insert checkbox) sensitivity.
;
SensitizeMyVis
; Realize the dialog box.
;
WIDGET_CONTROL, wMainBase, /REALIZE
; Start event loop.
;
XMANAGER, 'PromptUserMyVis', wMainBase, EVENT_HANDLER='HandleEventsMyVis'
; Remove widget state info.
;
PTR_FREE, psState
end ; PromptUserMyVis
; *****************************************************************************
; REGISTRATION FUNCTION
; *****************************************************************************
; -----------------------------------------------------------------------------
;
; Purpose: Register the Analysis PlugIn.
;
function MyVis
; Return the Analysis PlugIn Registration Structure.
;
RETURN, { $
type: 'Analysis_PlugIn', $ ; PlugIn type
title: 'My Vis...', $ ; PlugIn title
purpose: 'Do example visualizations.', $ ; PlugIn purpose
main_proc: 'PromptUserMyVis', $ ; main callback
apply_func: 'ApplyMyVis', $ ; apply callback
version: '5.0', $ ; IDL version
revision: '1.0' $ ; PlugIn version
}
end ; MyVis
; -----------------------------------------------------------------------------